function updateCalendar(id, withHours)
{
	var y = $(id+"_anio").options[$(id+"_anio").selectedIndex].value;
	var m = $(id+"_mes").selectedIndex+1;
	var d = $(id+"_dia").selectedIndex+1;
	
	if(m < 10)
	{
		m = "0"+m;
	}
	if(d < 10)
	{
		d = "0"+d;
	}
	
	if(withHours == '1')
    {
    	var hr = $(id+"_hora").options[$(id+"_hora").selectedIndex].value;
        var min = $(id+"_min").options[$(id+"_min").selectedIndex].value;
        var seg = $(id+"_seg").options[$(id+"_seg").selectedIndex].value;	
    	$(id).value = y+"-"+m+"-"+d+" "+hr+":"+min+":"+seg;
        
    }
    else
    {
    	$(id).value = y+"-"+m+"-"+d;
    }
}

function updateSelector(id)
{
	var date = $(id).value;
	var arDate = [];
	var arDate = date.split("-");
	$(id+"_anio").selectedIndex = -(parseInt(arDate[0])-<?= (date('Y')+(int)$_GET['yOffsetUp']) ?>);
	$(id+"_mes").selectedIndex = parseInt(arDate[1],10)-1;
	$(id+"_dia").selectedIndex =  parseInt(arDate[2],10)-1;
}

function setDays(id) {
  var y = $(id+"_anio").options[$(id+"_anio").selectedIndex].value;
  var m = $(id+"_mes").selectedIndex;
  var d;

  // find number of days in current month
  if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) {
	days = 30;
  }
  else if (m == 1) {
	// check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
	if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
	  days = 29;
	else
	  days = 28;
  }
  else {
	days = 31;
  }

  // if (days in new month > current days) then we must add the extra days
  if (days > $(id+"_dia").length) {
	for (i = $(id+"_dia").length; i < days; i++) {
	  $(id+"_dia").length = days;
	  $(id+"_dia").options[i].text = i + 1;
	  $(id+"_dia").options[i].value = i + 1;
	}
  }


  // if (days in new month < current days) then we must delete the extra days
  if (days < $(id+"_dia").length) {
	$(id+"_dia").length = days;
	if ($(id+"_dia").selectedIndex == -1)
	  $(id+"_dia").selectedIndex = days - 1;
  }
}
